#include "03_header.h"
#include <openssl/sha.h>

void hash_compute(char *sha1str,char *pathname)
{
    SHA_CTX ctx;
    SHA1_Init(&ctx);
    int fd=open(pathname,O_RDWR);
    char buf[4096];
    while(1)
    {
        bzero(buf,sizeof(buf));
        ssize_t sret=read(fd,buf,sizeof(buf));
        SHA1_Update(&ctx,buf,sret);
        if(sret==0)
        {
            break;
        }
    }
    unsigned char md[20];
    SHA1_Final(md,&ctx);
    bzero(sha1str,41);
    for(int i=0;i<20;i++)
    {
        char temp[3]={0};
        sprintf(temp,"%02x",md[i]);
        strcat(sha1str,temp);
    }
}

